package com.cxc.java8;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.LongPredicate;
import java.util.function.Predicate;

public class LambadUse {



    private static List<Apple>  filter(List<Apple> source, Predicate<Apple> predicate){
        ArrayList<Apple> list = new ArrayList<>();
        for(Apple  a:source){
            if (predicate.test(a)){
                list.add(a);
            }
        }
        return list;
    }

    private  static List<Apple>  filterByWeight(List<Apple> source, LongPredicate predicate){

        ArrayList<Apple> list = new ArrayList<>();
        for(Apple  a:source){
            if (predicate.test(a.getWeight())){
                list.add(a);
            }
        }
        return list;

    }


    private  static List<Apple>  filterByBiWeight(List<Apple> source, BiPredicate<String,Long> predicate){

        ArrayList<Apple> list = new ArrayList<>();
        for(Apple  a:source){
            if (predicate.test(a.getColor(),a.getWeight())){
                list.add(a);
            }
        }
        return list;

    }
    public static void main(String[] args) {

      /*  Runnable  r1 = () ->{
            System.out.println("hello");
        };

        process(r1);*/


        List<Apple> apples = Arrays.asList(new Apple("green", 150), new Apple("red", 120));

       /* List<Apple> green = filter(apples, apple -> apple.getColor().equals("green"));
        System.out.println(green);*/

       /* List<Apple> appList = filterByWeight(apples, w -> w>120);
        System.out.println(appList);*/

        List<Apple> result = filterByBiWeight(apples, (s,w)->s.equals("red") && w>100);
        System.out.println(result);




    }

    private static void process(Runnable r) {
            r.run();
    }

}
